package com.lovo.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lovo.project.bean.BuyInBean;
import com.lovo.project.service.BuyInService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

@RestController
@CrossOrigin
@RequestMapping("/buyin")
public class BuyInController {
    @Autowired
    BuyInService buyInService;

    @RequestMapping("/queryBuyInList")
    public Page<BuyInBean> queryBuyInList(Integer userId, Integer pg, Integer pgsize, String supplierName, String startTime, String endTime) {
        QueryWrapper<BuyInBean> queryWrapper = new QueryWrapper<>();
        if (userId > 0) {
            queryWrapper.eq("user_id", userId);
        }
        if (supplierName != null && supplierName != "") {
            queryWrapper.like("buyin_supplier_name", supplierName);
        }
        if (startTime != null && startTime!="") {
            queryWrapper.ge("buyin_time", startTime);
        }
        if (endTime != null && endTime!="") {
            queryWrapper.le("buyin_time", endTime);
        }
        Page<BuyInBean> page = new Page<>(pg, pgsize);
        Page<BuyInBean> pageInfo = buyInService.queryBuyInList(page, queryWrapper);
        return pageInfo;
    }

    @RequestMapping("/queryBuyIn")
    public BuyInBean queryBuyIn(Integer buyInId) {
        BuyInBean buyInBean = buyInService.queryBuyIn(buyInId);
        return buyInBean;
    }
}
